#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int N = 1000009; //100005

int n,maytakein,cnt;
struct match
{
	int start;
	int endd;
};
match M[N];
bool cmp(match x,match y)
{
	return x.endd < y.endd;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		cin >> M[i].start >> M[i].endd;
	}
	sort(M+1,M+1+n,cmp);
	for(int i=1;i<=n;i++)
	{
		if(maytakein <= M[i].start)
		{
			maytakein = M[i].endd;
			cnt++;
		}
	}
	cout << cnt;
	return 0;
}
